package com.item.util;

import java.io.File;

import jxl.Cell;
import jxl.Workbook;
import jxl.write.WritableCell;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class MyExcelUtils {
	public static WritableWorkbook checkSheetExists(Workbook wb, WritableWorkbook book, String filepath) throws Exception{
		File file = new File(filepath);
		if(!file.exists() || file.length() <= 0){
			book = Workbook.createWorkbook(file);
		}else{
			wb = Workbook.getWorkbook(file);
			book = Workbook.createWorkbook(file,wb);
		}
		// 首先判断是否已经包含相应的工作表了,如果有了就先删掉
//		Sheet[] sheets = book.getSheets();
//		for (int i = 0; i < sheets.length; i++) {
//			if (sheets[i].getName().equals(sheetName)) {
//				book.removeSheet(i);
//				break;
//			}
//		}
		return book;
	}
	
	public static WritableCell getCellByContent(WritableSheet sheet,int column,String content){
		int rows = sheet.getRows();
		for(int i = 0; i < rows; i++){
			WritableCell cell = sheet.getWritableCell(column, i);
			if(cell.getContents().contains(content)){
				return cell;
			}
		}
		return null;
	}

}
